<?php
/**
 * Created by PhpStorm.
 * User: yiyu
 * Email: smalleasyu@gmail.com
 * Date: 2020-01-30 12:48:32
 * Desc:
 */

namespace app\base\model\user;

use think\Model;

class UserAccountLog extends Model
{

    // 关闭自动写入时间戳
    protected $autoWriteTimestamp = false;

    protected $table = 'xy_user.xy_user_account_log';

    public static function hasAlreadyReceivedRegisterReward($user_id)
    {
        return UserAccountLog::field('log_id')->where('user_id', $user_id)->where('account_type',
            UserAccount::getLogAccountType(UserAccount::WISH_COIN))
            ->where('operation_type', 'register_give')->find();
    }

    /**
     * Desc: 获取流水列表
     * Date: 2020/2/19 9:56
     * Author: yiyu
     * @param $where
     * @param array $order
     * @param int $page
     * @param int $page_size
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static function getBillList($where, $order = [], $page = 1, $page_size = 10)
    {
        $query = self::where($where);

        if ($order) {
            $query->order($order);
        }

        $items = $query->paginate($page_size)->toArray();

        if ($items && isset($items['data']) && $items['data']) {
            array_walk($items['data'], function (&$item) {
                $item['operation_number'] = (float)$item['operation_number']; //去掉0
                if ($item['operation_number'] > 0) {
                    $item['operation_number'] = '+' . $item['operation_number'];//补上+号
                }
                $item['account_count'] = (float)$item['account_count']; //去掉0
            });
        }

        return $items;

    }


    public static function isFirstSupport($user_id, $group_id)
    {
        return UserAccountLog::where('user_id', $user_id)->where('group_id', $group_id)
            ->where('operation_type', UserAccount::FIRST_SUPPORT_OPERATION_TYPE)
            ->field('log_id')
            ->find();
    }

}